package cn.edu.lingnan.service.impl;



import cn.edu.lingnan.mapper.UserExamMapper;
import cn.edu.lingnan.service.ExamDetailService;
import cn.edu.lingnan.user.pojos.PageBean;
import cn.edu.lingnan.user.vos.ExamDetailVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
@Slf4j
public class ExamDetailServiceImpl implements ExamDetailService {

    @Autowired
    private UserExamMapper userExamMapper;

    @Override
    public PageBean<ExamDetailVO> getExamDetailsByUserId(Integer userId, Integer page, Integer pageSize) {
        // 计算偏移量
        Integer offset = (page - 1) * pageSize;

        // 查询分页数据
        List<ExamDetailVO> examDetails = userExamMapper.selectExamDetailsByUserId(userId, offset, pageSize);

        // 查询总数
        Integer total = userExamMapper.countExamedDetailsByUserId(userId);
        log.info("查询总数：{}", total);

        // 封装分页结果
        PageBean<ExamDetailVO> pageBean = new PageBean<>();
        pageBean.setTotal(total);
        pageBean.setRows(examDetails);

        return pageBean;
    }
}